package com.epam.edu.task04.Parking;

import java.util.logging.Logger;

public class Car extends Thread {
	private Parking<ParkingPlace> pool;
	private static Logger logger = Logger.getLogger("Car");

	public Car(Parking<ParkingPlace> pool) {
		this.pool = pool;
	}

	@Override
	public void run() {
		ParkingPlace place = null;
		try {
			place = pool.getResource(new java.util.Random().nextInt(1000));
			logger.info("Car №" + this.getId() + " parked on the place №"
					+ place.getPlaceId());
			place.using();
		} catch (Exception e) {
			logger.info("Car №" + this.getId() + " lost ->" + e.getMessage());
		} finally {
			if (place != null) {
				logger.info("Car №" + this.getId() + " : " + place.getPlaceId()
						+ " place released");
				pool.returnResource(place);
			}
		}
	}

}
